Expression

open class Expression

The value for any layout property, paint property, or filter may be specified as an expression. An expression defines a formula for computing the value of the property using the operators described below. The set of expression operators provided by Mapbox GL includes:

  • Element
  • Mathematical operators for performing arithmetic and other operations on numeric values
  • Logical operators for manipulating boolean values and making conditional decisions
  • String operators for manipulating strings
  • Data operators, providing access to the properties of source features
  • Camera operators, providing access to the parameters defining the current map view

Expressions are represented as JSON arrays. The first element of an expression array is a string naming the expression operator, e.g. "*"or "case". Subsequent elements (if any) are the arguments to the expression. Each argument is either a literal value (a string, number, boolean, or null), or another expression array.

Data expression: a data expression is any expression that access feature data -- that is, any expression that uses one of the data operators:get,has,id,geometry-type, or properties. Data expressions allow a feature's properties to determine its appearance. They can be used to differentiate features within the same layer and to create data visualizations.

Camera expression: a camera expression is any expression that uses the zoom operator. Such expressions allow the the appearance of a layer to change with the map's zoom level. Camera expressions can be used to create the appearance of depth and to control data density.

Composition: a single expression may use a mix of data operators, camera operators, and other operators. Such composite expressions allows a layer's appearance to be determined by a combination of the zoom level and individual feature properties.

Example expression:


FillLayer fillLayer = new FillLayer("layer-id", "source-id");
fillLayer.setProperties(
  fillColor(
    interpolate( linear(), zoom(),
      stop(12, step(get("stroke-width"),
        color(Color.BLACK),
        stop(1f, color(Color.RED)),
        stop(2f, color(Color.WHITE)),
        stop(3f, color(Color.BLUE))
      )),
      stop(15, step(get("stroke-width"),
        color(Color.BLACK),
        stop(1f, color(Color.YELLOW)),
        stop(2f, color(Color.LTGRAY)),
        stop(3f, color(Color.CYAN))
      )),
      stop(18, step(get("stroke-width"),
        color(Color.BLACK),
        stop(1f, color(Color.WHITE)),
        stop(2f, color(Color.GRAY)),
        stop(3f, color(Color.GREEN))
      ))
    )
  )
);

Constructors

Link copied to clipboard
open fun Expression(@NonNull operator: String, @Nullable arguments: Array<Expression>)
Creates an expression from its operator and varargs expressions.

Types

Link copied to clipboard
open class Array
Expression array type.
Link copied to clipboard
class Converter
Converts a JsonArray or a raw expression to a Java expression.
Link copied to clipboard
open class ExpressionLiteral : Expression, Expression.ValueExpression
ExpressionLiteral wraps an object to be used as a literal in an expression.
Link copied to clipboard
open class FormatEntry
Holds format entries used in a format expression.
Link copied to clipboard
open class FormatOption : Expression.Option
Holds format options used in a formatEntry that builds a format expression.
Link copied to clipboard
Expression interpolator type.
Link copied to clipboard
open class NumberFormatOption : Expression.Option
Holds format options used in a numberFormat expression.
Link copied to clipboard
open class Stop
Expression stop type.

Functions

Link copied to clipboard
open fun abs(expression: Expression): Expression
open fun abs(@NonNull number: Number): Expression
Returns the absolute value of the input.
Link copied to clipboard
Gets the value of a cluster property accumulated so far.
Link copied to clipboard
open fun acos(@NonNull number: Expression): Expression
open fun acos(@NonNull number: Number): Expression
Returns the arccosine of the input.
Link copied to clipboard
open fun all(@NonNull input: Array<Expression>): Expression
Returns `true` if all the inputs are `true`, `false` otherwise.
Link copied to clipboard
open fun any(@NonNull input: Array<Expression>): Expression
Returns `true` if any of the inputs are `true`, `false` otherwise.
Link copied to clipboard
open fun array(@NonNull input: Expression): Expression
Asserts that the input is an array (optionally with a specific item type and length).
Link copied to clipboard
open fun asin(@NonNull number: Expression): Expression
open fun asin(@NonNull number: Number): Expression
Returns the arcsine of the input.
Link copied to clipboard
open fun at(@NonNull number: Expression, @NonNull expression: Expression): Expression
open fun at(@NonNull number: Number, @NonNull expression: Expression): Expression
Retrieves an item from an array.
Link copied to clipboard
open fun atan(@NonNull number: Expression): Expression
open fun atan(@NonNull number: Number): Expression
Returns the arctangent of the input.
Link copied to clipboard
open fun bool(@NonNull input: Array<Expression>): Expression
Asserts that the input value is a boolean.
Link copied to clipboard
open fun ceil(expression: Expression): Expression
open fun ceil(@NonNull number: Number): Expression
Returns the smallest integer that is greater than or equal to the input.
Link copied to clipboard
Evaluates each expression in turn until the first non-null value is obtained, and returns that value.
Link copied to clipboard
open fun collator(caseSensitive: Boolean, diacriticSensitive: Boolean): Expression
open fun collator(caseSensitive: Expression, diacriticSensitive: Expression): Expression
open fun collator(caseSensitive: Boolean, diacriticSensitive: Boolean, locale: Locale): Expression
open fun collator(caseSensitive: Expression, diacriticSensitive: Expression, locale: Expression): Expression
Returns a collator for use in locale-dependent comparison operations.
Link copied to clipboard
open fun color(@ColorInt color: Int): Expression
Expression literal utility method to convert a color int to an color expression Example usage:

FillLayer fillLayer = new FillLayer("layer-id", "source-id");
fillLayer.setProperties(
    fillColor(color(Color.GREEN))
);
Link copied to clipboard
open fun concat(@NonNull input: Array<String>): Expression
Returns a string consisting of the concatenation of the inputs.
Link copied to clipboard
open fun cos(@NonNull number: Expression): Expression
open fun cos(@NonNull number: Number): Expression
Returns the cosine of the input.
Link copied to clipboard
Interpolates using the cubic bezier curve defined by the given control points.
Link copied to clipboard
open fun distance(@NonNull geoJson: GeoJson): Expression
Retrieves the shortest distance between two geometries.
Link copied to clipboard
open fun division(@NonNull first: Expression, @NonNull second: Expression): Expression
open fun division(@NonNull first: Number, @NonNull second: Number): Expression
Returns the result of floating point division of the first input by the second.
Link copied to clipboard
open fun downcase(@NonNull input: String): Expression
Returns the input string converted to lowercase.
Link copied to clipboard
open fun e(): Expression
Returns the mathematical constant e.
Link copied to clipboard
open fun eq(@NonNull compareOne: Expression, compareTwo: Boolean): Expression
open fun eq(@NonNull compareOne: Expression, @NonNull compareTwo: Expression): Expression
open fun eq(@NonNull compareOne: Expression, @NonNull compareTwo: Number): Expression
open fun eq(@NonNull compareOne: Expression, @NonNull compareTwo: String): Expression
open fun eq(@NonNull compareOne: Expression, @NonNull compareTwo: Expression, @NonNull collator: Expression): Expression
open fun eq(@NonNull compareOne: Expression, @NonNull compareTwo: String, @NonNull collator: Expression): Expression
Returns true if the input values are equal, false otherwise.
Link copied to clipboard
open fun equals(@Nullable o: Any): Boolean
Indicates whether some other object is "equal to" this one.
Link copied to clipboard
Interpolates exponentially between the stops just less than and just greater than the input.
Link copied to clipboard
open fun floor(expression: Expression): Expression
open fun floor(@NonNull number: Number): Expression
Returns the largest integer that is less than or equal to the input.
Link copied to clipboard
Returns formatted text containing annotations for use in mixed-format text-field entries.
Link copied to clipboard
Returns a format entry that can be used in format to create formatted text fields.
Link copied to clipboard
Gets the feature's geometry type: Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon.
Link copied to clipboard
open fun get(@NonNull input: Expression): Expression
open fun get(@NonNull input: String): Expression
Retrieves a property value from the current feature's properties, or from another object if a second argument is provided.
open fun get(@NonNull key: Expression, @NonNull object: Expression): Expression
open fun get(@NonNull key: String, @NonNull object: Expression): Expression
Retrieves a property value from another object.
Link copied to clipboard
open fun gt(@NonNull compareOne: Expression, @NonNull compareTwo: Expression): Expression
open fun gt(@NonNull compareOne: Expression, @NonNull compareTwo: Number): Expression
open fun gt(@NonNull compareOne: Expression, @NonNull compareTwo: String): Expression
open fun gt(@NonNull compareOne: Expression, @NonNull compareTwo: Expression, @NonNull collator: Expression): Expression
open fun gt(@NonNull compareOne: Expression, @NonNull compareTwo: String, @NonNull collator: Expression): Expression
Returns true if the first input is strictly greater than the second, false otherwise.
Link copied to clipboard
open fun gte(@NonNull compareOne: Expression, @NonNull compareTwo: Expression): Expression
open fun gte(@NonNull compareOne: Expression, @NonNull compareTwo: Number): Expression
open fun gte(@NonNull compareOne: Expression, @NonNull compareTwo: String): Expression
open fun gte(@NonNull compareOne: Expression, @NonNull compareTwo: Expression, @NonNull collator: Expression): Expression
open fun gte(@NonNull compareOne: Expression, @NonNull compareTwo: String, @NonNull collator: Expression): Expression
Returns true if the first input is greater than or equal to the second, false otherwise.
Link copied to clipboard
open fun has(@NonNull key: Expression): Expression
open fun has(@NonNull key: String): Expression
Tests for the presence of an property value in the current feature's properties.
open fun has(@NonNull key: Expression, @NonNull object: Expression): Expression
open fun has(@NonNull key: String, @NonNull object: Expression): Expression
Tests for the presence of an property value from another object.
Link copied to clipboard
open fun hashCode(): Int
Returns a hash code value for the expression.
Link copied to clipboard
Gets the kernel density estimation of a pixel in a heatmap layer, which is a relative measure of how many data points are crowded around a particular pixel.
Link copied to clipboard
open fun id(): Expression
Gets the feature's id, if it has one.
Link copied to clipboard
open fun image(@NonNull input: Expression): Expression
Returns image expression for use in '*-pattern' and 'icon-image' layer properties.
Link copied to clipboard
open fun in(@NonNull needle: Expression, @NonNull haystack: Expression): Expression
open fun in(@NonNull needle: Number, @NonNull haystack: Expression): Expression
open fun in(@NonNull needle: String, @NonNull haystack: Expression): Expression
Retrieves whether an item exists in an array or a substring exists in a string.
Link copied to clipboard
open fun indexOf(@NonNull keyword: Expression, @NonNull input: Expression): Expression
open fun indexOf(@NonNull keyword: Expression, @NonNull input: Expression, @NonNull fromIndex: Expression): Expression
Returns the first position at which a `needle` can be found in a `haystack`.
Link copied to clipboard
Produces continuous, smooth results by interpolating between pairs of input and output values (\"stops\").
Link copied to clipboard
open fun isSupportedScript(expression: Expression): Expression
Returns true if the input string is expected to render legibly.
Link copied to clipboard
open fun length(@NonNull expression: Expression): Expression
open fun length(@NonNull input: String): Expression
Gets the length of an array or string.
Link copied to clipboard
open fun let(@Size(min = 1) input: Array<Expression>): Expression
Binds input to named variables, which can then be referenced in the result expression using var or var.
Link copied to clipboard
interpolates linearly between the pair of stops just less than and just greater than the input.
Link copied to clipboard
Gets the progress along a gradient line.
Link copied to clipboard
open fun literal(bool: Boolean): Expression
Create a literal boolean expression.
open fun literal(@NonNull number: Number): Expression
Create a literal number expression.
open fun literal(@NonNull object: Any): Expression
Create a literal object expression.
open fun literal(@NonNull array: Array<Any>): Expression
Create a literal array expression
open fun literal(@NonNull string: String): Expression
Create a literal string expression.
Link copied to clipboard
open fun ln(number: Expression): Expression
open fun ln(@NonNull number: Number): Expression
Returns the natural logarithm of the input.
Link copied to clipboard
open fun ln2(): Expression
Returns mathematical constant ln(2).
Link copied to clipboard
open fun log10(@NonNull number: Expression): Expression
open fun log10(@NonNull number: Number): Expression
Returns the base-ten logarithm of the input.
Link copied to clipboard
open fun log2(@NonNull number: Expression): Expression
open fun log2(@NonNull number: Number): Expression
Returns the base-two logarithm of the input.
Link copied to clipboard
open fun lt(@NonNull compareOne: Expression, @NonNull compareTwo: Expression): Expression
open fun lt(@NonNull compareOne: Expression, @NonNull compareTwo: Number): Expression
open fun lt(@NonNull compareOne: Expression, @NonNull compareTwo: String): Expression
open fun lt(@NonNull compareOne: Expression, @NonNull compareTwo: Expression, @NonNull collator: Expression): Expression
open fun lt(@NonNull compareOne: Expression, @NonNull compareTwo: String, @NonNull collator: Expression): Expression
Returns true if the first input is strictly less than the second, false otherwise.
Link copied to clipboard
open fun lte(@NonNull compareOne: Expression, @NonNull compareTwo: Expression): Expression
open fun lte(@NonNull compareOne: Expression, @NonNull compareTwo: Number): Expression
open fun lte(@NonNull compareOne: Expression, @NonNull compareTwo: String): Expression
open fun lte(@NonNull compareOne: Expression, @NonNull compareTwo: Expression, @NonNull collator: Expression): Expression
open fun lte(@NonNull compareOne: Expression, @NonNull compareTwo: String, @NonNull collator: Expression): Expression
Returns true if the first input is less than or equal to the second, false otherwise.
Link copied to clipboard
open fun match(@NonNull @Size(min = 2) input: Array<Expression>): Expression
open fun match(@NonNull input: Expression, @NonNull defaultOutput: Expression, @NonNull stops: Array<Expression.Stop>): Expression
Selects the output whose label value matches the input value, or the fallback value if no match is found.
Link copied to clipboard
open fun max(@Size(min = 1) numbers: Array<Expression>): Expression
open fun max(@Size(min = 1) numbers: Array<Number>): Expression
Returns the maximum value of the inputs.
Link copied to clipboard
open fun min(@Size(min = 1) numbers: Array<Expression>): Expression
open fun min(@Size(min = 1) numbers: Array<Number>): Expression
Returns the minimum value of the inputs.
Link copied to clipboard
open fun mod(@NonNull first: Expression, @NonNull second: Expression): Expression
open fun mod(@NonNull first: Number, @NonNull second: Number): Expression
Returns the remainder after integer division of the first input by the second.
Link copied to clipboard
open fun neq(compareOne: Expression, compareTwo: Boolean): Expression
Returns true if the input values are equal, false otherwise.
open fun neq(@NonNull compareOne: Expression, @NonNull compareTwo: Expression): Expression
open fun neq(@NonNull compareOne: Expression, @NonNull compareTwo: Expression, @NonNull collator: Expression): Expression
open fun neq(@NonNull compareOne: Expression, @NonNull compareTwo: String, @NonNull collator: Expression): Expression
Returns true if the input values are not equal, false otherwise.
open fun neq(@NonNull compareOne: Expression, @NonNull compareTwo: Number): Expression
open fun neq(@NonNull compareOne: Expression, @NonNull compareTwo: String): Expression
Returns `true` if the input values are not equal, `false` otherwise.
Link copied to clipboard
open fun not(input: Boolean): Expression
open fun not(@NonNull input: Expression): Expression
Logical negation.
Link copied to clipboard
Asserts that the input value is a number.
Link copied to clipboard
Converts the input number into a string representation using the providing formatting rules.
Link copied to clipboard
open fun object(@NonNull input: Expression): Expression
Asserts that the input value is an object.
Link copied to clipboard
open fun pi(): Expression
Returns the mathematical constant pi.
Link copied to clipboard
open fun pow(@NonNull first: Expression, @NonNull second: Expression): Expression
open fun pow(@NonNull first: Number, @NonNull second: Number): Expression
Returns the result of raising the first input to the power specified by the second.
Link copied to clipboard
open fun product(@Size(min = 2) numbers: Array<Expression>): Expression
open fun product(@Size(min = 2) numbers: Array<Number>): Expression
Returns the product of the inputs.
Link copied to clipboard
Gets the feature properties object.
Link copied to clipboard
open fun raw(@NonNull rawExpression: String): Expression
Returns a DSL equivalent of a raw expression.
Link copied to clipboard
open fun resolvedLocale(collator: Expression): Expression
Returns the IETF language tag of the locale being used by the provided collator.
Link copied to clipboard
open fun rgb(@NonNull red: Expression, @NonNull green: Expression, @NonNull blue: Expression): Expression
open fun rgb(@NonNull red: Number, @NonNull green: Number, @NonNull blue: Number): Expression
Creates a color value from red, green, and blue components, which must range between 0 and 255, and an alpha component of 1.
Link copied to clipboard
open fun rgba(@NonNull red: Expression, @NonNull green: Expression, @NonNull blue: Expression, @NonNull alpha: Expression): Expression
open fun rgba(@NonNull red: Number, @NonNull green: Number, @NonNull blue: Number, @NonNull alpha: Number): Expression
Creates a color value from red, green, blue components, which must range between 0 and 255, and an alpha component which must range between 0 and 1.
Link copied to clipboard
open fun round(expression: Expression): Expression
open fun round(@NonNull number: Number): Expression
Rounds the input to the nearest integer.
Link copied to clipboard
open fun sin(@NonNull number: Expression): Expression
open fun sin(@NonNull number: Number): Expression
Returns the sine of the input.
Link copied to clipboard
open fun sqrt(@NonNull number: Expression): Expression
Returns the square root of the input Example usage:

CircleLayer circleLayer = new CircleLayer("layer-id", "source-id");
circleLayer.setProperties(
    circleRadius(sqrt(pi()))
);
open fun sqrt(@NonNull number: Number): Expression
Returns the square root of the input Example usage:

CircleLayer circleLayer = new CircleLayer("layer-id", "source-id");
circleLayer.setProperties(
    circleRadius(sqrt(25.0f))
);
Link copied to clipboard
open fun step(@NonNull input: Expression, @NonNull defaultOutput: Expression, @NonNull stops: Array<Expression>): Expression
open fun step(@NonNull input: Expression, @NonNull defaultOutput: Expression, stops: Array<Expression.Stop>): Expression
open fun step(@NonNull input: Expression, @NonNull defaultOutput: Number, stops: Array<Expression>): Expression
open fun step(@NonNull input: Expression, @NonNull defaultOutput: Number, stops: Array<Expression.Stop>): Expression
open fun step(@NonNull input: Number, @NonNull defaultOutput: Expression, stops: Array<Expression>): Expression
open fun step(@NonNull input: Number, @NonNull defaultOutput: Expression, stops: Array<Expression.Stop>): Expression
open fun step(@NonNull input: Number, @NonNull defaultOutput: Number, stops: Array<Expression>): Expression
open fun step(@NonNull input: Number, @NonNull defaultOutput: Number, stops: Array<Expression.Stop>): Expression
Produces discrete, stepped results by evaluating a piecewise-constant function defined by pairs of input and output values (\"stops\").
Link copied to clipboard
open fun stop(@NonNull stop: Any, @NonNull value: Any): Expression.Stop
Produces a stop value.
Link copied to clipboard
Asserts that the input value is a string.
Link copied to clipboard
open fun subtract(@NonNull number: Expression): Expression
open fun subtract(@NonNull number: Number): Expression
Returns the result of subtracting a number from 0.
open fun subtract(@NonNull first: Expression, @NonNull second: Expression): Expression
open fun subtract(@NonNull first: Number, @NonNull second: Number): Expression
Returns the result of subtracting the second input from the first.
Link copied to clipboard
open fun sum(@Size(min = 2) numbers: Array<Expression>): Expression
open fun sum(@Size(min = 2) numbers: Array<Number>): Expression
Returns the sum of the inputs.
Link copied to clipboard
open fun switchCase(@NonNull @Size(min = 1) input: Array<Expression>): Expression
Selects the first output whose corresponding test condition evaluates to true.
Link copied to clipboard
open fun tan(@NonNull number: Expression): Expression
open fun tan(@NonNull number: Number): Expression
Returns the tangent of the input.
Link copied to clipboard
open fun toArray(): Array<Any>
Converts the expression to Object array representation.
Link copied to clipboard
open fun toBool(@NonNull input: Expression): Expression
Converts the input value to a boolean.
Link copied to clipboard
open fun toColor(@NonNull input: Expression): Expression
Converts the input value to a color.
Link copied to clipboard
Converts the input value to a number, if possible.
Link copied to clipboard
open fun toRgba(@NonNull expression: Expression): Expression
Returns a four-element array containing the input color's red, green, blue, and alpha components, in that order.
Link copied to clipboard
open fun toString(): String
Returns a string representation of the object that matches the definition set in the style specification.
Converts the input value to a string.
Link copied to clipboard
open fun typeOf(@NonNull input: Expression): Expression
Returns a string describing the type of the given value.
Link copied to clipboard
open fun upcase(@NonNull string: Expression): Expression
open fun upcase(@NonNull string: String): Expression
Returns the input string converted to uppercase.
Link copied to clipboard
open fun var(@NonNull expression: Expression): Expression
open fun var(@NonNull variableName: String): Expression
References variable bound using let.
Link copied to clipboard
open fun within(@NonNull polygon: Polygon): Expression
Link copied to clipboard
open fun zoom(): Expression
Gets the current zoom level.

Inheritors

Link copied to clipboard
Link copied to clipboard